﻿/*
**预审贷款页面
*/
Chenxin.UI.PreliminaryApplyPage = Chenxin.extend(Chenxin.UI.AddPageCommon,{
    actionUrl:"/service/logic/PreliminaryApply.ashx",
    createForm:function(){
		return new Chenxin.UI.PreliminaryApplyForm({
			//type:'numal',
			scope:this
		});
	},
    customerInit:function(){
    },
    initEvent:function(){
        var objPa = this;
        /*************事件：提交*************/
        $("#aSubmit").click(function(){
            if(objPa.form.PreliminaryBaseInfo != undefined){
                objPa.form.op = "upd";
            }
            if((objPa.form.PreliminaryBaseInfo == undefined && objPa.form.HouseInfo == undefined) || (objPa.form.PreliminaryBaseInfo != undefined && objPa.form.PreliminaryBaseInfo.HouseId == undefined)){
                objPa.form.op = "qz";
            }
            objPa.form.save();
            return false;
        });
        /*************事件：关闭*************/
        $('#aClose').live('click', function() {
            window.location.href = "/page/Preliminary_Info/ShowListPreliminary.aspx";
        });
    }
});

Chenxin.UI.PreliminaryApplyForm = Chenxin.extend(Chenxin.UI.AddFormCommon,{
    actionUrl:"/service/logic/PreliminaryApply.ashx",
    //type: 'numal',
    id: 'PreliminaryApply_form',
//    protectBy: '',
//    ppcVal: {},
    //下拉框初始
    createComboList:function(){
        var jsonInitVal = this.initComboVal();
        /****************************房源信息*************************/
        //竣工日期
        var comboCompleteYear = new Chenxin.UI.BuildingYearCombo({
            containerId: '#CompleteYear',
            tbxWidth: 120,
            required:true,
            initValue:jsonInitVal.CompleteYear
        });
        //建筑类型
        var comboBuildingType = new Chenxin.UI.ParameterCombo({
            containerId: '#BuildingType',
            name: 'BuildingType',
            key: 'Building.Type',
            inModelType: 'txt',
            autoLoad: true,
            tbxWidth: 120,
            required: true,
            initValue: jsonInitVal.BuildingType
        });
        /****************************预审申请信息*************************/
        //申请部门
        var comboAppDepartId = new Chenxin.UI.DepartTreeCombo({
			containerId: '#AppDepartId',
			textBoxId: 'AppDepartId',
			name:'AppDepartId',
			inModelType:'all',
			txtModelName:'AppDepartName',
			required:true,
			afterSetValue: function(val, txt) {
                if (val != this.defVal) {
                    comboAppemployeeId.loadUser(val)
                }
            },
			onSelected:function(){
				if( this.getValue() != this.defVal ){
					comboAppemployeeId.loadUser(this.getValue());
				}
			}
		});
		//申请人员
		var comboAppemployeeId =new Chenxin.UI.RichModelTreeCombo({
            textBoxId:'txtAppEmployeeId',
            containerId:'#txtAppEmployeeId',
            inModelType:'all',
			txtModelName:'AppEmployeeName',
            required:true,
            singleSelect:true,
			name:'AppEmployeeId'
        });
//        //预审机构（城市）
//        var comboPreliminaryCityId= new Chenxin.UI.StructCombo({
//			param:{op:'getcity'},
//			containerId: '#PreliminaryCityId',
//			name:'PreliminaryCityId',
//			inModelType:'all',
//			txtModelName:'PreliminaryCityName',
//			initValue:jsonInitVal.PreliminaryCityId,
//			tbxWidth: 120,
//			onSelected:function(){
//				if(this.getValue()==this.defVal){
//				}else{
//					comboPreliminaryCompanyId.param.fatherid=this.getValue();
//					comboPreliminaryCompanyId.reload();
//				}
//				comboPreliminaryCompanyId.clearItems();
//				comboPreliminaryDepartId.clearItems();
//			},
//			afterSetValue:function(newVal,oldVal){
//			    if( newVal != "请选择" ){
//			        comboPreliminaryCompanyId.param.fatherid=newVal;
//				    comboPreliminaryCompanyId.reload(jsonInitVal.PreliminaryCompanyId);
//				}
//			}
//		});
//		//预审机构（部门）
//        var comboPreliminaryDepartId= new Chenxin.UI.StructCombo({
//            param:{op:'getcompanydeparts'},
//            containerId: '#PreliminaryDepartId',
//            inModelType:'all',
//			txtModelName:'PreliminaryDepartName',
//			initValue:jsonInitVal.PreliminaryDepartId,
//            tbxWidth: 120,
//            colWidth:120,
//            colNum:4,
//            autoLoad:false,
//			required: true,
//			hasPage: true,
//			pageSize:60,
//			onSelected:function(){},
//			afterSetValue:function(newVal,oldVal){
//			    if( newVal != "请选择" ){}
//			}
//        });
//        //预审机构（公司）
//        var comboPreliminaryCompanyId= new Chenxin.UI.StructCombo({
//			param:{op:'getcompany'},
//			containerId: '#PreliminaryCompanyId',
//			name:'PreliminaryCompanyId',
//			inModelType:'all',
//			txtModelName:'PreliminaryCompanyName',
//			initValue:jsonInitVal.PreliminaryCompanyId,
//			tbxWidth: 120,
//			autoLoad:false,
//			onSelected:function(){
//				if(this.getValue()==this.defVal){
//					comboPreliminaryDepartId.clearItems();
//				}else{
//					comboPreliminaryDepartId.param.op = "getcompanydeparts";
//					comboPreliminaryDepartId.param.fatherid=this.getValue();
//					comboPreliminaryDepartId.reload();
//				}
//				comboPreliminaryDepartId.clearItems();
//			},
//			afterSetValue:function(newVal,oldVal){
//			    if( newVal != "请选择" ){
//					comboPreliminaryDepartId.param.op = "getcompanydeparts";
//			        comboPreliminaryDepartId.param.fatherid=newVal;
//				    comboPreliminaryDepartId.reload(jsonInitVal.PreliminaryDepartId);
//				}
//			}
//		});
        //贷款类型
        var comboLoanInfo= new Chenxin.UI.Combo({
            containerId: '#LoanInfo',
            tbxWidth: 120,
            colWidth:80,
            items:comboCommon.LoanInfoType
        });
        /****************************预审其他信息*************************/
        //原贷款银行
        var comboOldLoanBank= new Chenxin.UI.Combo({
            containerId: '#OldLoanBank',
            tbxWidth: 120,
            colWidth:80,
            items:comboCommon.BankInfo
        });
        return [comboBuildingType,comboCompleteYear,comboAppDepartId,comboAppemployeeId,comboLoanInfo,comboOldLoanBank];
    },
    //文本框初始
    initFormValidator:function(){
            /****************************房源信息*************************/
        //房源地址
        $("#txtAddress").formValidator({
            validatorgroup: this.id,
            onshow: "请输入房源地址！",
            onfocus: "房源地址为必输项",
            oncorrect: " "
        }).inputValidator({ 
            min: 1,
            empty: {
                leftempty: false,
                rightempty: false,
                emptyerror: "房源地址不能为空！"
            },
            onerror: "房源地址不能为空！"
        });
        //建筑面积
        $("#txtBuildingArea").formValidator({
            validatorgroup: this.id,
            onshow: "请输入建筑面积！",
            onfocus: "建筑面积为必输项",
            oncorrect: " "
        }).inputValidator({ 
            min: 1,
            empty: {
                leftempty: false,
                rightempty: false,
                emptyerror: "建筑面积不能为空！"
            },
            onerror: "建筑面积不能为空！"
        });
        //总楼层
        $("#txtTotal_Floor").formValidator({
            validatorgroup: this.id,
            onshow: "请输入总楼层！",
            onfocus: "总楼层为必输项",
            oncorrect: " "
        }).inputValidator({ 
            min: 1,
            empty: {
                leftempty: false,
                rightempty: false,
                emptyerror: "总楼层不能为空！"
            },
            onerror: "总楼层不能为空！"
        });
        //成交总价
        $("#txtSalePrice_T").formValidator({
            validatorgroup: this.id,
            onshow: "请输入成交总价！",
            onfocus: "格式：整数或最多保留2位小数,单位：万元",
            oncorrect: " "
        }).inputValidator({ 
            min: 1,
            empty: {
                leftempty: false,
                rightempty: false,
                emptyerror: "成交总价不能为空！"
            },
            onerror: "成交总价不能为空！"
        }).regexValidator({
            regexp:"decmal7",
            datatype:"enum",
            onerror:"格式不正确"
        });
        //联系电话
        $("#txtEmpPhone").formValidator({
            validatorgroup: this.id,
            onshow: "请输入联系电话！",
            onfocus: "联系电话为必输项",
            oncorrect: " "
        }).inputValidator({ 
            min: 1,
            empty: {
                leftempty: false,
                rightempty: false,
                emptyerror: "联系电话不能为空！"
            },
            onerror: "联系电话不能为空！"
        });
        /****************************预审申请信息*************************/
        //申请人员
        $("#txtAppEmployeeId").formValidator({
            validatorgroup: this.id,
            onshow: "请输入申请人员！",
            onfocus: "申请人员为必输项",
            oncorrect: " "
        }).inputValidator({ 
            min: 1,
            empty: {
                leftempty: false,
                rightempty: false,
                emptyerror: "申请人员不能为空！"
            },
            onerror: "申请人员不能为空！"
        });
        //贷款总额
        $("#txtLoanTotalMoney").formValidator({
            validatorgroup: this.id,
            onshow: "请输入总贷款额！",
            onfocus: "总贷款额为必输项,单位：万元",
            oncorrect: " "
        }).inputValidator({ 
            min: 1,
            empty: {
                leftempty: false,
                rightempty: false,
                emptyerror: "总贷款额不能为空！"
            },
            onerror: "总贷款额不能为空！"
        });
        /****************************预审其他信息*************************/
        //上家姓名
        $("#txtSaleName").formValidator({
            validatorgroup: this.id,
            onshow: "请输入上家姓名！",
            onfocus: "上家姓名为必输项",
            oncorrect: " "
        }).inputValidator({ 
            min: 1,
            empty: {
                leftempty: false,
                rightempty: false,
                emptyerror: "上家姓名不能为空！"
            },
            onerror: "上家姓名不能为空！"
        });
        //上家身份证
        $("#txtSaleIDCard").formValidator({
            validatorgroup: this.id,
            onshow: "请输入上家身份证！",
            onfocus: "上家身份证为必输项",
            oncorrect: " "
        }).inputValidator({ 
            min: 1,
            empty: {
                leftempty: false,
                rightempty: false,
                emptyerror: "上家身份证不能为空！"
            },
            onerror: "上家身份证不能为空！"
        });
        //原贷款金额
        $("#txtOldLoanMoney").formValidator({
            validatorgroup: this.id,
            onshow: "请输入原贷款金额！",
            onfocus: "原贷款金额为必输项,单位：万元",
            oncorrect: " "
        }).inputValidator({ 
            min: 1,
            empty: {
                leftempty: false,
                rightempty: false,
                emptyerror: "原贷款金额不能为空！"
            },
            onerror: "原贷款金额不能为空！"
        });
        //剩余贷款金额
        $("#txtOldRestMoney").formValidator({
            validatorgroup: this.id,
            onshow: "请输入剩余贷款金额！",
            onfocus: "剩余贷款金额为必输项,单位：万元",
            oncorrect: " "
        }).inputValidator({ 
            min: 1,
            empty: {
                leftempty: false,
                rightempty: false,
                emptyerror: "剩余贷款金额不能为空！"
            },
            onerror: "剩余贷款金额不能为空！"
        });

        if ($("input[name=Receipt]").val()==true) {
            $("#txtSaleName").unFormValidator(false);
            $("#txtSaleIDCard").unFormValidator(false);
        } else {
            $("#txtSaleName").unFormValidator(true);
            $("#txtSaleIDCard").unFormValidator(true);
        }
        if ($("input[name=Mortgage]").val()==true) {
            $("#txtSaleName").unFormValidator(false);
            $("#txtSaleIDCard").unFormValidator(false);
            $("#txtOldRestMoney").unFormValidator(false);
            $("#txtOldLoanMoney").unFormValidator(false);
        } else {
            $("#txtSaleName").unFormValidator(true);
            $("#txtSaleIDCard").unFormValidator(true);
            $("#txtOldRestMoney").unFormValidator(true);
            $("#txtOldLoanMoney").unFormValidator(true);
        }
    },
    manualPreCheck:function(){
        var bRet = true;
        var strJson = ""
        
        //贷款人信息
        $("#tbBuyer tr").each(function(){
            var objIDNum = $(this).find("input[name=IDNum]:eq(0)");
            var objCustomerName = $(this).find("input[name=CustomerName]:eq(0)");
            if( objIDNum.val() == "" || objCustomerName.val() == ""){
                alert("请输入贷款人信息");
                objCustomerName.focus();
                bRet =  false;
                return false;
            }
            
            var trJson={};
            $(this).find("input").each(function(){
               //单选框
               if(this.type.toLowerCase() == "checkbox"){
                   //被选中
                   if($(this).attr("checked")){
                       trJson[this.name] = true;
                   }else{
                       trJson[this.name] = false;
                   }
               }
            });

            if(trJson.toString() != "{}")
            {
               strJson = trJson.toString();
            }
            if(strJson == "{Married:\"true\"}")
            {
               var objBowner = $(this).find("input[name=BOwner]:eq(0)");
               var objSpousesName = $(this).find("input[name=SpousesName]:eq(0)");
               var objSpousesIDNum =$(this).find("input[name=SpousesIDNum]:eq(0)");
               if(objBowner.val() == "on" && objSpousesName.val()=="" && objSpousesIDNum.val()=="")
               {
                   alert("请输入配偶信息！");
                   objSpousesName.focus();
                   bRet =  false;
                   return false;
               }
               else if(objBowner.val() == "on" && objSpousesName.val()=="" && objSpousesIDNum.val()!="")
               {
                   alert("请输入配偶姓名！");
                   objSpousesName.focus();
                   bRet =  false;
                   return false;
               }
               else if(objBowner.val() == "on" && objSpousesName.val()!="" && objSpousesIDNum.val()=="")
               {
                   alert("请输入配偶身份证！");
                   objSpousesIDNum.focus();
                   bRet =  false;
                   return false;
               }
            }
        });
        
        //原贷款人信息
        $("#tbOther tr").each(function(){
           var trJson={};
           $(this).find("input").each(function(){
               //单选框
               if(this.type.toLowerCase() == "radio"){
                   //被选中
                   if($(this).attr("checked")){
                       trJson[this.name] = true;
                   }else{
                       trJson[this.name] = false;
                   }
               }
           });
           
           if(trJson.toString() != "{}")
           {
               strJson = trJson.toString();
           }
           
           if(strJson == "{Receipt:\"true\",Mortgage:\"false\",IsOneYear:\"false\"}" || strJson == "{Receipt:\"true\",Mortgage:\"false\",IsOneYear:\"true\"}"){
               var objSaleName = $(this).find("input[name=SaleName]:eq(0)");
               var objSaleIDCard = $(this).find("input[name=SaleIDCard]:eq(0)");
               if( objSaleName.val() == "" || objSaleIDCard.val() == ""){
                   alert("请输入预审其他信息");
                   objSaleName.focus();
                   bRet =  false;
                   return false;
               }
            }
            
            if(strJson == "{Receipt:\"true\",Mortgage:\"true\",IsOneYear:\"false\"}" || strJson == "{Receipt:\"false\",Mortgage:\"true\",IsOneYear:\"true\"}"
                || strJson == "{Receipt:\"true\",Mortgage:\"true\",IsOneYear:\"true\"}" || strJson == "{Receipt:\"false\",Mortgage:\"true\",IsOneYear:\"false\"}"){
               var objSaleName = $(this).find("input[name=SaleName]:eq(0)");
               var objSaleIDCard = $(this).find("input[name=SaleIDCard]:eq(0)");
               var objOldRestMoney = $(this).find("input[name=OldRestMoney]:eq(0)");
               var objOldLoanMoney = $(this).find("input[name=OldLoanMoney]:eq(0)");
               //var objOldLoanBank = $("#OldLoanBank");
               if( objSaleName.val() == "" || objSaleIDCard.val() == "" || objOldRestMoney.val() == "" || objOldLoanMoney.val() == ""){
                   alert("请输入预审其他信息");
                   objSaleName.focus();
                   bRet =  false;
                   return false;
               }
            }
        });
        return bRet;
    },
    initEvent:function(){
        /*************事件：收件收据控制*************/
        $("input[name='Receipt']").click(function () {
            $('#tr_showReceipt')[this.value=="true"?'show':'hide']();
        });
        /*************事件：转按揭控制*************/
        $("input[name='Mortgage']").click(function () {
            $('#tr_showReceipt')[this.value=="true"?'show':'hide']();
            $('#tr_showMortgage')[this.value=="true"?'show':'hide']();
            $('#div_showRemark')[this.value=="true"?'show':'hide']();
        });
        /*************事件：只输入数字*************/
        $("input[name='SalePrice_T']").keydown(function (event) {
            if (((event.keyCode > 47) && (event.keyCode < 58)) || 
                  ((event.keyCode > 95) && (event.keyCode < 106)) ||
                  (event.keyCode == 110) || (event.keyCode == 8) ||   
                  (event.keyCode == 190)) {
                return true;      
            } else {      
                return false;      
            }      
        });
        $("input[name='LoanTotalMoney']").keydown(function (event) {
            if (((event.keyCode > 47) && (event.keyCode < 58)) || 
                  ((event.keyCode > 95) && (event.keyCode < 106)) ||
                  (event.keyCode == 110) || (event.keyCode == 8) ||   
                  (event.keyCode == 190)) {
                return true;      
            } else {      
                return false;      
            }      
        });
        $("input[name='OldRestMoney']").keydown(function (event) {
            if (((event.keyCode > 47) && (event.keyCode < 58)) || 
                  ((event.keyCode > 95) && (event.keyCode < 106)) ||
                  (event.keyCode == 110) || (event.keyCode == 8) ||   
                  (event.keyCode == 190)) {
                return true;      
            } else {      
                return false;      
            }      
        });
        $("input[name='OldLoanMoney']").keydown(function (event) {
            if (((event.keyCode > 47) && (event.keyCode < 58)) || 
                  ((event.keyCode > 95) && (event.keyCode < 106)) ||
                  (event.keyCode == 110) || (event.keyCode == 8) ||   
                  (event.keyCode == 190)) {
                return true;      
            } else {      
                return false;      
            }      
        });
        /*************事件：添加出售方*************/
        $("#aAddSaler").click(function(){
            var htmlTr = "<tr>";
            htmlTr =  htmlTr + "<td style='width: 362px'>";
            htmlTr =  htmlTr + "    <input type=text name='SaleNamePublic' class='inputbox_n fl' style=\"width:342px\" />";
            htmlTr =  htmlTr + "</td>";
            htmlTr =  htmlTr + "<td style='width: 395px'>";
            htmlTr =  htmlTr + "     <input type=text name='SaleIDCardPublic' class='inputbox_n fl' style=\"width:373px\"/>";
            htmlTr =  htmlTr + "</td>";
            htmlTr =  htmlTr + "<td style='text-align:center;width: 57px;'>";
            htmlTr =  htmlTr + "     <a href='javascript:void(0)' name='aDelSaler'>删除</a>";
            htmlTr =  htmlTr + "</td>";
            htmlTr =  htmlTr + "</tr>";
            
            var objOwerTr = $(this).parents("tr:first");
            $(objOwerTr).before(htmlTr);
            $(objOwerTr).prev().find("input:eq(1)").focus();
        });
        
        /*************事件：导入出售方信息*************/
        $("#aLoadSaler").click(function(){
            if(confirm("是否从签约报备导入卖方信息！")){
                if( $("#ctl00_main_hidLoadSaler").val() != ""){
                    var loadSaler = eval("(" + $("#ctl00_main_hidLoadSaler").val() + ")");
                    this.preSalerInfo = loadSaler;
                    //绑定上家
                    if(this.preSalerInfo != undefined)
                    {
                        $("#tbSaler tbody").children("tr:eq(0)").remove();
                        var tbHtml;
                        for(var iCnt = this.preSalerInfo.length - 1; iCnt >= 0; iCnt-- )
                        {
                            tbHtml = "";
                            tbHtml = tbHtml + "<tr>";
                            tbHtml = tbHtml + "    <td style='width: 362px'>";
                            tbHtml = tbHtml + "        <input type=text name=\"SaleNamePublic\" value=\"" + (this.preSalerInfo[iCnt]).SaleNamePublic + "\" class=\"inputbox_n fl\" style=\"width:342px\" />";
                            tbHtml = tbHtml + "    </td>";
                            tbHtml = tbHtml + "    <td style='width: 395px'>";
                            if((this.preSalerInfo[iCnt]).SaleIDCardPublic != null && (this.preSalerInfo[iCnt]).SaleIDCardPublic != "")
                            {
                                tbHtml = tbHtml + "        <input type=text name=\"SaleIDCardPublic\" value=\"" + (this.preSalerInfo[iCnt]).SaleIDCardPublic + "\" class=\"inputbox_n fl\" style=\"width:373px\" />";
                            }else{
                                tbHtml = tbHtml + "        <input type='text' name=\"SaleIDCardPublic\" class=\"inputbox_n fl\" />";
                            }
                            tbHtml = tbHtml + "    </td>";
                            tbHtml = tbHtml + "    <td style='text-align:center;width: 57px;'>";
                            tbHtml = tbHtml + "        <a href=\"javascript:void(0)\" name=\"aDelSaler\">删除</a>";
                            tbHtml = tbHtml + "    </td>";
                            tbHtml = tbHtml + "</tr>";
                            $("#tbSaler tbody").children("tr:eq(0)").before(tbHtml);
                        }
                    }
                }
            }
            return false;
        });
            
        /*************事件：删除出售方*************/
        $("A[name=aDelSaler]").live("click",function(){
            if(confirm("确定要删除吗？")){
                var objOwerTr = $(this).parents("tr:first");
                $(objOwerTr).remove();
            }
        });
        
        /*************事件：添加贷款人*************/
        $("#aAddBuyer").click(function(){
            var htmlTr = "<tr>";
            htmlTr =  htmlTr + "    <td style='text-align:center;height: 30px'>";
            htmlTr =  htmlTr + "        <input type='radio'name='BOwner' />";
            htmlTr =  htmlTr + "    </td>";
            htmlTr =  htmlTr + "    <td style='text-align:center;height: 30px;width: 75px;'>";
            htmlTr =  htmlTr + "        <input type='text' name='CustomerName' class='inputbox_n fl' style='width:65px' />";
            htmlTr =  htmlTr + "    </td>";
            htmlTr =  htmlTr + "    <td style='text-align:center;height: 30px;width: 135px;'>";
            htmlTr =  htmlTr + "         <input type='text' name='IDNum' class='inputbox_n fl' style='width:125px' />";
            htmlTr =  htmlTr + "    </td>";
            htmlTr =  htmlTr + "    <td style='text-align:center;height: 30px;'>";
            htmlTr =  htmlTr + "        <input type='text' name='GJJNum' class='inputbox_n fl' style='width:100px' />";
            htmlTr =  htmlTr + "    </td>";
            htmlTr =  htmlTr + "    <td style='text-align:center;height: 30px;width: 75px;'>";
            htmlTr =  htmlTr + "        <input type='text' name='SpousesName' class='inputbox_n fl' style='width:65px' />";
            htmlTr =  htmlTr + "    </td>";
            htmlTr =  htmlTr + "    <td style='text-align:center;height: 30px;width: 135px;'>";
            htmlTr =  htmlTr + "         <input type='text' name='SpousesIDNum' class='inputbox_n fl' style='width:125px' />";
            htmlTr =  htmlTr + "    </td>";
            htmlTr =  htmlTr + "    <td style='text-align:center;height: 30px;'>";
            htmlTr =  htmlTr + "        <input type='text' name='SpousesGJJNum' class='inputbox_n fl' style='width:100px' />";
            htmlTr =  htmlTr + "    </td>";
            htmlTr =  htmlTr + "    <td style='text-align:center;height: 30px;width: 61px;'>";
            htmlTr =  htmlTr + "         <a href='javascript:void(0)' name='aDelBuyer'>删除</a>";
            htmlTr =  htmlTr + "    </td>";
            htmlTr =  htmlTr + "</tr>";

            var objOwerTr = $(this).parents("tr:first");
            $(objOwerTr).before(htmlTr);
            $(objOwerTr).prev().find("input:eq(0)").focus();
        });
        
        /*************事件：导入买方信息*************/
        $("#aLoadBuyer").click(function(){
            if(confirm("是否从签约报备导入买方信息！")){
                if( $("#ctl00_main_hidLoadBuyer").val() != "" ){
                    var loadBuyer = eval("(" + $("#ctl00_main_hidLoadBuyer").val() + ")");
                    this.preBuyerInfo = loadBuyer;
                    //绑定贷款人信息
                    if(this.preBuyerInfo != undefined )
                    {
                        $("#tbBuyer tbody").children("tr:eq(0)").remove();
                        var tbHtml;
                        for(var iCnt = this.preBuyerInfo.length - 1; iCnt >= 0; iCnt-- )
                        {
                            tbHtml = "";
                            tbHtml = tbHtml + "<tr>";
                            tbHtml =  tbHtml + "    <td style='text-align:center;'>";
                            if( (this.preBuyerInfo[iCnt]).BOwner == true ){
                                tbHtml =  tbHtml + "        <input type=radio name='BOwner' checked />";
                            }else{
                                tbHtml =  tbHtml + "        <input type=radio name='BOwner' />";
                            }
                            tbHtml = tbHtml + "    </td>";
                            tbHtml = tbHtml + "    <td style='text-align:center;height: 30px;width: 55px;'>";
                            tbHtml = tbHtml + "        <input type='text' name=\"CustomerName\" value=\"" + (this.preBuyerInfo[iCnt]).CustomerName + "\" class=\"inputbox_n fl\" style=\"width:55px\" />";
                            tbHtml = tbHtml + "    </td>";
                            tbHtml = tbHtml + "    <td style='text-align:center;height: 30px;width: 135px;'>";
                            tbHtml = tbHtml + "        <input type='text' name=\"IDNum\" value=\"" + (this.preBuyerInfo[iCnt]).IDNum + "\" class=\"inputbox_n fl\" style=\"width:130px\" />";
                            tbHtml = tbHtml + "    </td>";
                            tbHtml = tbHtml + "    <td style='text-align:center;height: 30px;'>";
                            tbHtml = tbHtml + "        <input type='text' name=\"GJJNum\" value=\"" + (this.preBuyerInfo[iCnt]).GJJNum + "\" class=\"inputbox_n fl\" style=\"width:100px\" />";
                            tbHtml = tbHtml + "    </td>";
                            tbHtml = tbHtml + "    <td style='text-align:center;height: 55px;'>";
                            if((this.preBuyerInfo[iCnt]).SpousesName != null && (this.preBuyerInfo[iCnt]).SpousesName != "")
                            {
                                tbHtml = tbHtml + "        <input type='text' name=\"SpousesName\" value=\"" + (this.preBuyerInfo[iCnt]).SpousesName + "\" class=\"inputbox_n fl\" style=\"width:55px\" />";
                            }else{
                                tbHtml = tbHtml + "        <input type='text' name=\"SpousesName\" class=\"inputbox_n fl\" style=\"width:55px\" />";
                            }
                            tbHtml = tbHtml + "    </td>";
                            tbHtml = tbHtml + "    <td style='text-align:center;height: 30px;width: 135px;'>";
                            if((this.preBuyerInfo[iCnt]).SpousesIDNum != null && (this.preBuyerInfo[iCnt]).SpousesIDNum != "")
                            {
                                tbHtml = tbHtml + "        <input type='text' name=\"SpousesIDNum\" value=\"" + (this.preBuyerInfo[iCnt]).SpousesIDNum + "\" class=\"inputbox_n fl\" style=\"width:130px\" />";
                            }else{
                                tbHtml = tbHtml + "        <input type='text' name=\"SpousesIDNum\" class=\"inputbox_n fl\" style=\"width:130px\" />";
                            }
                            tbHtml = tbHtml + "    </td>";
                            tbHtml = tbHtml + "    <td style='text-align:center;height: 30px;'>";
                            if((this.preBuyerInfo[iCnt]).SpousesGJJNum != null && (this.preBuyerInfo[iCnt]).SpousesGJJNum != "")
                            {
                                tbHtml = tbHtml + "        <input type=text name=\"SpousesGJJNum\" value=\"" + (this.preBuyerInfo[iCnt]).SpousesGJJNum + "\" class=\"inputbox_n fl\" style=\"width:100px\" />";
                            }else{
                                tbHtml = tbHtml + "        <input type='text' name=\"SpousesGJJNum\" class=\"inputbox_n fl\" style=\"width:100px\" />";
                            }
                            tbHtml = tbHtml + "    </td>";
                            tbHtml = tbHtml + "    <td style='text-align:center;height: 30px;width: 61px;'>";
                            tbHtml = tbHtml + "        <a href=\"javascript:void(0)\" name=\"aDelBuyer\">删除</a>";
                            tbHtml = tbHtml + "    </td>";
                            tbHtml = tbHtml + "</tr>";
                            $("#tbBuyer tbody").children("tr:eq(0)").before(tbHtml);
                        }
                    }
                }
            }
            return false;
        });
            
        /*************事件：删除贷款人*************/
        $("A[name=aDelBuyer]").live("click",function(){
            if(confirm("确定要删除吗？")){
                var objOwerTr = $(this).parents("tr:first");
                $(objOwerTr).remove();
            }
        });
    },
    saveSucc:function(){
        //提交成功后转到查询页面
        window.location.href = "/page/Preliminary_Info/ShowListPreliminary.aspx";
    },
    afterGetFormJson:function(json){
        var JsonList = [];
        var trJson={};
        this.form.additionalParam = {};

        //出售方信息
        $("#tbSaler tr").each(function(){
            $(this).find("input").each(function(){
                if( this.value != "" ){
                    trJson[this.name] = this.value;
                }
            });
            if(trJson.toString() != "{}"){
                JsonList.push(trJson);
            }
            trJson = {};
        });
        //出售方信息
        if( JsonList.toString() != "" ){
            this.form.additionalParam.lsPreSaler = "[" + JsonList.toString() + "]";
        }
        
        JsonList = [];
        //买方信息
        $("#tbBuyer tr").each(function(){
            $(this).find("input").each(function(){
                //单选框
                if(this.type.toLowerCase() == "radio"){
                    //被选中
                    if($(this).attr("checked")){
                        trJson[this.name] = true;
                    }else{
                        trJson[this.name] = false;
                    }
                }else{
                    if( this.value != "" ){
                        trJson[this.name] = this.value;
                    }
                }
            });
            if(trJson.toString() != "{}" & trJson.toString() != "{BOwner:\"true\"}" & trJson.toString() != "{BOwner:\"false\"}" & trJson.toString() != "{Married:\"on\"}"){
                JsonList.push(trJson);
            }
            trJson = {};
        });
        //买方信息
        if( JsonList.toString() != "" ){
            this.form.additionalParam.lsPreBuyer = "[" +  JsonList.toString() + "]";
        }
        //删除出售方，买方详细信息
        delete json.BOwner;
        delete json.CustomerName;
        delete json.IDNum;
        delete json.GJJNum;
        delete json.SpousesName;
        delete json.SpousesIDNum;
        delete json.SpousesGJJNum;
        delete json.SaleNamePublic;
        delete json.SaleIDCardPublic;
        //房源地址
        if( this.form.HouseInfo != undefined ){
            json.EmpCityId = this.form.HouseInfo.CityId;
            json.EmpCompanyId = this.form.HouseInfo.CompanyId;
            json.EmpCompanyName = this.form.HouseInfo.CompanyName;
            json.EmpDepartId = this.form.HouseInfo.OprDepartId;
            json.EmployeeId = this.form.HouseInfo.OprPersonId;
        }
        delete json.NewAddress;
        delete json.BuyerStatus;
        delete json.PreliminaryCityId;
        delete json.PreliminaryCompanyId;
        delete json.PreliminaryDepartId;
        delete json.Married;
    },
    initForm:function(){
        //初始房源信息
        if($("#ctl00_main_hidHouseInfo").val() != ""){
            var houseInfo = eval("(" + $("#ctl00_main_hidHouseInfo").val() + ")");
            //有房源信息
            this.HouseInfo = houseInfo;
            
            //申请部门
            var appdepart = eval("(" + $("#ctl00_main_hidAppDepart").val() + ")");
            this.AppDepart = appdepart;
        }
        //预审信息
        if($("#ctl00_main_hidPreliminaryInfo").val() != ""){
            var PreliminaryBaseInfo = eval("(" + $("#ctl00_main_hidPreliminaryInfo").val() + ")");
            this.PreliminaryBaseInfo = PreliminaryBaseInfo;
            //房源源地址
            this.PreliminaryBaseInfo.Address = this.PreliminaryBaseInfo.Address;
            //出售方信息
            if( $("#ctl00_main_hidPreSalerInfo").val() != ""){
                var preSalerInfo = eval("(" + $("#ctl00_main_hidPreSalerInfo").val() + ")");
                this.preSalerInfo = preSalerInfo;
            }
            //买方信息
            if( $("#ctl00_main_hidPreBuyerInfo").val() != "" ){
                var preBuyerInfo = eval("(" + $("#ctl00_main_hidPreBuyerInfo").val() + ")");
                this.preBuyerInfo = preBuyerInfo;
            }
        }
    },
    initComboVal:function(){
        var jsonInitVal = {};
            jsonInitVal.AppDepartId = "请选择";
            jsonInitVal.AppEmployeeId = "请选择";
            jsonInitVal.PreliminaryDepartId = "请选择";
            jsonInitVal.LoanInfo = "请选择";
            jsonInitVal.OrderBank = "请选择";
        if( this.HouseInfo != undefined ){
            jsonInitVal.CompleteYear = this.HouseInfo.CompleteYear;
            jsonInitVal.BuildingType = this.HouseInfo.BuildingType;
        }
        else if(this.PreliminaryBaseInfo != undefined)
        {
            jsonInitVal.AppCityId = this.PreliminaryBaseInfo.AppCityId;
            jsonInitVal.AppCityName = this.PreliminaryBaseInfo.AppCityName;
            jsonInitVal.AppCompanyId = this.PreliminaryBaseInfo.AppCompanyId;
            jsonInitVal.AppCompanyName = this.PreliminaryBaseInfo.AppCompanyName;
//            if(this.PreliminaryBaseInfo.AppDepartId != "00000000-0000-0000-0000-000000000000")
//            {
//                jsonInitVal.AppDepartId = this.PreliminaryBaseInfo.AppDepartId;
//                jsonInitVal.AppDepartName = this.PreliminaryBaseInfo.AppDepartName;
//            }
//            else
//            {
//                jsonInitVal.AppDepartId = "请选择";
//                jsonInitVal.AppDepartName = "请选择";
//            }
//            if(this.PreliminaryBaseInfo.AppEmployeeId != "00000000-0000-0000-0000-000000000000")
//            {
//                jsonInitVal.AppEmployeeId = this.PreliminaryBaseInfo.AppEmployeeId;
//                jsonInitVal.AppEmployeeName = this.PreliminaryBaseInfo.AppEmployeeName;
//            }
//            else
//            {
//                this.PreliminaryBaseInfo.AppEmployeeId = null;
//                this.PreliminaryBaseInfo.AppEmployeeName = null;
//                jsonInitVal.AppEmployeeId = "请选择";
//                jsonInitVal.AppEmployeeName = "请选择";
//            }
            jsonInitVal.PreliminaryCityId = this.PreliminaryBaseInfo.PreliminaryCityId;
            jsonInitVal.PreliminaryCityName = this.PreliminaryBaseInfo.PreliminaryCityName;
            jsonInitVal.PreliminaryCompanyId = this.PreliminaryBaseInfo.PreliminaryCompanyId;
            jsonInitVal.PreliminaryCompanyName = this.PreliminaryBaseInfo.PreliminaryCompanyName;
            jsonInitVal.PreliminaryDepartId = this.PreliminaryBaseInfo.PreliminaryDepartId;
            jsonInitVal.PreliminaryDepartName = this.PreliminaryBaseInfo.PreliminaryDepartName;
            jsonInitVal.LoanInfo = this.PreliminaryBaseInfo.LoanInfo;
            jsonInitVal.OrderBank = this.PreliminaryBaseInfo.OrderBank;
            jsonInitVal.BuildingType = this.PreliminaryBaseInfo.BuildingType;
        }else{
            jsonInitVal.CompleteYear = "请选择";
            jsonInitVal.BuildingType = "请选择";
        }
        return jsonInitVal;
    },
    loadDefVal:function(){
        //房源信息
        if( this.HouseInfo != undefined ){
            var tbHouse = "tbHouse";
            this.HouseInfo.Address = this.HouseInfo.DetailAddress;
            this.HouseInfo.EmpDepartName = this.HouseInfo.OprDepart;
            this.HouseInfo.EmployeeName = this.HouseInfo.OprPerson;
            this.HouseInfo.SalePrice = this.HouseInfo.SalePrice_T;
            //绑定页面房源部分
            Chenxin.Fn.setFormValue(tbHouse,{},this.HouseInfo,true);
            Chenxin.Fn.setFormValue(this.id,this.comboList,this.AppDepart,true);
        }

        if(this.PreliminaryBaseInfo != undefined)
        {
            //绑定预审信息
			delete this.PreliminaryBaseInfo.BuildingType;
            Chenxin.Fn.setFormValue(this.id,this.comboList,this.PreliminaryBaseInfo,true);
            //绑定贷款人信息
            if(this.preBuyerInfo != undefined )
            {
                $("#tbBuyer tbody").children("tr:eq(0)").remove();
                var tbHtml;              
                for(var iCnt = this.preBuyerInfo.length - 1; iCnt >= 0; iCnt-- )
                {
                    tbHtml = "";
                    tbHtml = tbHtml + "<tr>";
                    tbHtml =  tbHtml + "    <td style='text-align:center;'>";
                    if( (this.preBuyerInfo[iCnt]).BOwner == true ){
                        tbHtml =  tbHtml + "        <input type=radio name='BOwner' checked />";
                    }else{
                        tbHtml =  tbHtml + "        <input type=radio name='BOwner' />";
                    }
                    tbHtml =  tbHtml + "    </td>";
                    tbHtml = tbHtml + "    <td style='text-align:center;height: 30px;width: 55px;'>";
                    tbHtml = tbHtml + "        <input type='text' name=\"CustomerName\" value=\"" + (this.preBuyerInfo[iCnt]).CustomerName + "\" class=\"inputbox_n fl\" style=\"width:55px\" />";
                    tbHtml = tbHtml + "    </td>";
                    tbHtml = tbHtml + "    <td style='text-align:center;height: 30px;width: 135px;'>";
                    tbHtml = tbHtml + "        <input type='text' name=\"IDNum\" value=\"" + (this.preBuyerInfo[iCnt]).IDNum + "\" class=\"inputbox_n fl\" style=\"width:130px\" />";
                    tbHtml = tbHtml + "    </td>";
                    tbHtml = tbHtml + "    <td style='text-align:center;height: 30px;'>";
                    tbHtml = tbHtml + "        <input type='text' name=\"GJJNum\" value=\"" + (this.preBuyerInfo[iCnt]).GJJNum + "\" class=\"inputbox_n fl\" style=\"width:100px\" />";
                    tbHtml = tbHtml + "    </td>";
                    tbHtml = tbHtml + "    <td style='text-align:center;height: 55px;'>";
                    if((this.preBuyerInfo[iCnt]).SpousesName != null && (this.preBuyerInfo[iCnt]).SpousesName != "")
                    {
                        tbHtml = tbHtml + "        <input type='text' name=\"SpousesName\" value=\"" + (this.preBuyerInfo[iCnt]).SpousesName + "\" class=\"inputbox_n fl\" style=\"width:55px\" />";
                    }else{
                        tbHtml = tbHtml + "        <input type='text' name=\"SpousesName\" class=\"inputbox_n fl\" style=\"width:55px\" />";
                    }
                    tbHtml = tbHtml + "    </td>";
                    tbHtml = tbHtml + "    <td style='text-align:center;height: 30px;width: 135px;'>";
                    if((this.preBuyerInfo[iCnt]).SpousesIDNum != null && (this.preBuyerInfo[iCnt]).SpousesIDNum != "")
                    {
                        tbHtml = tbHtml + "        <input type='text' name=\"SpousesIDNum\" value=\"" + (this.preBuyerInfo[iCnt]).SpousesIDNum + "\" class=\"inputbox_n fl\" style=\"width:130px\" />";
                    }else{
                        tbHtml = tbHtml + "        <input type='text' name=\"SpousesIDNum\" class=\"inputbox_n fl\" style=\"width:130px\" />";
                    }
                    tbHtml = tbHtml + "    </td>";
                    tbHtml = tbHtml + "    <td style='text-align:center;height: 30px;'>";
                    if((this.preBuyerInfo[iCnt]).SpousesGJJNum != null && (this.preBuyerInfo[iCnt]).SpousesGJJNum != "")
                    {
                        tbHtml = tbHtml + "        <input type=text name=\"SpousesGJJNum\" value=\"" + (this.preBuyerInfo[iCnt]).SpousesGJJNum + "\" class=\"inputbox_n fl\" style=\"width:100px\" />";
                    }else{
                        tbHtml = tbHtml + "        <input type='text' name=\"SpousesGJJNum\" class=\"inputbox_n fl\" style=\"width:100px\" />";
                    }
                    tbHtml = tbHtml + "    </td>";
                    tbHtml = tbHtml + "    <td style='text-align:center;height: 30px;width: 61px;'>";
                    tbHtml = tbHtml + "        <a href=\"javascript:void(0)\" name=\"aDelBuyer\">删除</a>";
                    tbHtml = tbHtml + "    </td>";
                    tbHtml = tbHtml + "</tr>";
                    $("#tbBuyer tbody").children("tr:eq(0)").before(tbHtml);
                 }
             }

            //绑定上家
            if(this.preSalerInfo != undefined)
            {
                $("#tbSaler tbody").children("tr:eq(0)").remove();
                var tbHtml;
                for(var iCnt = this.preSalerInfo.length - 1; iCnt >= 0; iCnt-- )
                {
                    tbHtml = "";
                    tbHtml = tbHtml + "<tr>";
                    tbHtml = tbHtml + "    <td style='width: 362px'>";
                    tbHtml = tbHtml + "        <input type=text name=\"SaleNamePublic\" value=\"" + (this.preSalerInfo[iCnt]).SaleNamePublic + "\" class=\"inputbox_n fl\" style=\"width:342px\" />";
                    tbHtml = tbHtml + "    </td>";
                    tbHtml = tbHtml + "    <td style='width: 395px'>";
                    if((this.preSalerInfo[iCnt]).SaleIDCardPublic != null && (this.preSalerInfo[iCnt]).SaleIDCardPublic != "")
                    {
                        tbHtml = tbHtml + "        <input type=text name=\"SaleIDCardPublic\" value=\"" + (this.preSalerInfo[iCnt]).SaleIDCardPublic + "\" class=\"inputbox_n fl\" style=\"width:373px\" />";
                    }else{
                        tbHtml = tbHtml + "        <input type='text' name=\"SaleIDCardPublic\" class=\"inputbox_n fl\" />";
                    }
                    tbHtml = tbHtml + "    </td>";
                    tbHtml = tbHtml + "    <td style='text-align:center;width: 57px;'>";
                    tbHtml = tbHtml + "        <a href=\"javascript:void(0)\" name=\"aDelSaler\">删除</a>";
                    tbHtml = tbHtml + "    </td>";
                    tbHtml = tbHtml + "</tr>";
                    $("#tbSaler tbody").children("tr:eq(0)").before(tbHtml);
                 }
             }
         }
        
        var strJson = "";
        //原贷款人信息
        $("#tbOther tr").each(function(){
           var trJson={};
           $(this).find("input").each(function(){
               //单选框
               if(this.type.toLowerCase() == "radio"){
                   //被选中
                   if($(this).attr("checked")){
                       trJson[this.name] = true;
                   }else{
                       trJson[this.name] = false;
                   }
               }
           });
           
           if(trJson.toString() != "{}")
           {
               strJson = trJson.toString();
           }
           
           if(strJson == "{Receipt:\"true\",Mortgage:\"false\",IsOneYear:\"false\"}" || strJson == "{Receipt:\"true\",Mortgage:\"false\",IsOneYear:\"true\"}"){
                $('#tr_showReceipt').show();
            }
            
            if(strJson == "{Receipt:\"true\",Mortgage:\"true\",IsOneYear:\"false\"}" || strJson == "{Receipt:\"false\",Mortgage:\"true\",IsOneYear:\"true\"}"
                || strJson == "{Receipt:\"true\",Mortgage:\"true\",IsOneYear:\"true\"}" || strJson == "{Receipt:\"false\",Mortgage:\"true\",IsOneYear:\"false\"}"){
                $('#tr_showReceipt').show();
                $('#tr_showMortgage').show();
                $('#div_showRemark').show();
            }
        });
    },
	initComponent:function(){
		Chenxin.UI.PreliminaryApplyForm.superclass.initComponent.call(this);
	}
});

getcity = true; //设置需要获取城市下拉框数据

$(document).ready(function(){
    var objPage = new Chenxin.UI.PreliminaryApplyPage();
});